package jedistest;

import com.google.gson.Gson;
import java.util.List;
import redis.clients.jedis.JedisPooled;
import redis.clients.jedis.search.*;

/**
 * Created with IntelliJ IDEA. Description:
 *
 * @author lzy
 * @since 2024-03-14 下午6:02
 */
public class RedisJsonTest {
  public static void main(String[] args) {
    JedisPooled client = new JedisPooled("10.2.54.200", 6380);
    final Gson gson = new Gson();

    /*        Student maya = new Student("Maya", "Jayavant");
    client.jsonSet("student:111", gson.toJson(maya));

    Student oliwia = new Student("Oliwia", "Jagoda");
    client.jsonSet("student:112", gson.toJson(oliwia));*/

    /*client.jsonSetLegacy("student:111", maya);
    client.jsonSetWithEscape("student:112", oliwia);*/

    final Student s = client.jsonGet("student:111", Student.class);
    System.out.println(s);

    /*Schema schema =
        new Schema().addTextField("$.firstName", 1.0).addTextField("$" + ".lastName", 1.0);

    IndexDefinition rule = new IndexDefinition(IndexDefinition.Type.JSON).setPrefixes("student:");

    client.ftCreate("student-index", IndexOptions.defaultOptions().setDefinition(rule), schema);*/

    Query q = new Query("@\\$\\" + ".firstName:maya*");
    SearchResult mayaSearch = client.ftSearch("student-index", q);

    List<Document> docs = mayaSearch.getDocuments();
    for (Document doc : docs) {
      System.out.println(doc);
    }
  }
}
